<?php
/**
 *
 * LICENSE
 *
 * This source file is subject to the new BSD license that is bundled
 * with this package in the file LICENSE.txt.
 *
 * This license is also available via the world-wide-web at
 * http://itdapps.ncsu.edu/bsd.txt
 *
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to itappdev@ncsu.edu so we can send you a copy immediately.
 *
 * @package    User
 * @copyright  Copyright (c) 2007 NC State University Information Technology Division
 * @license    http://itdapps.ncsu.edu/bsd.txt  BSD License
 * @author     Jason Austin <jason_austin@ncsu.edu>
 * @author     Garrison Locke <garrison_locke@ncsu.edu>
 * @see        http://itdapps.ncsu.edu
 * @version    SVN: $Id: ActionLog.php 155 2007-07-19 19:44:26Z jfaustin@EOS.NCSU.EDU $
 */

/**
 * 
 * @package    User
 * @category   Model
 * @copyright  Copyright (c) 2007 NC State University Information Technology Division
 *
 */
class Gdata_Apps_User 
{
    //const CRUD_ACCOUNT_URI = 'https://apps-apis.google.com/a/feeds/[[domain]]/user/2.0/[[username]]';
    
    protected $_domain = null;
    protected $_username = null;
    protected $_password = null;
    protected $_gdataClient = null;    
    
    public function __construct()
    {
        $this->_domain = Zend_Registry::get('gdataDomain');
        $this->_username = Zend_Registry::get('gdataUsername');
        $this->_password = Zend_Registry::get('gdataPassword');
        
        try {
           $this->_gdataClient = Zend_Gdata_ClientLogin::getHttpClient($this->_username . '@' . $this->_domain, $this->_password, 'apps');
        } catch (Zend_Gdata_App_AuthException $ae) {
           echo 'Problem authenticating: ' . $ae->getMessage();
        }
    }
    
    public function find($username)
    {
        
        $gdata = new Zend_Gdata_Gapps($this->_gdataClient, $this->_domain);
                       
        return $gdata->retrieveUser($username);       
        
        //$url = str_replace(array('[[domain]]', '[[username]]'), array($this->_domain, $username), self::CRUD_ACCOUNT_URI);
        /**
        $cls = new StdClass();
        $cls->userId = $userId;
        $cls->firstName = 'test';
        $cls->lastName = 'user';
        
        return $cls;
        **/
        
        /*
        $request = new Google_Gdata_Request();
        $request->setUrl($url)
                ->setMethod(Google_Gdata_Request::GET)
                ->setConsumerKey(Zend_Registry::get('gdataOauthKey'))
                ->setConsumerSecret(Zend_Registry::get('gdataOauthSecret'))
                ->setRequestorId($username . '@' . $this->_domain)
                ;
                
        $thisUser = $request->send();
        */
    }
}